$(document).ready(function(){
    $(".dropdown-toggle, .menu").click(function (e) {
        var $li = $(this).parent("li").toggleClass('open'); 
        return false; 
    });
});
$('a.maya').click(function(event){
    event.preventDefault();
    var tableData = $('tbody.objectEventTableBody').html();
    $('tbody.objectEventTableBody').html('<tr><th>10</th>  <th>XEP</th>   <th>76</th>      <th>67</th></tr>' + tableData);
});
$('a.maya2').click(function(event){
    event.preventDefault();
    setInterval(ajaxRequest, 5 * 1000);
});


function ajaxRequestComplete(rsp) {
    //update table with a data
    $('div.eventTablePlaceholder').html(rsp);
    var tabledata = $('div.eventTablePlaceholder').find('tbody.eventTableBody').html();
    //var tabledataPrev = $('tbody.objectEventTableBody').html();
    //$('tbody.objectEventTableBody').html(tabledata + tabledataPrev);
    $('tbody.eventTableBody').html(tabledata);
    //update params
    $('div.eventTableSize').html($('#eventTable >tbody >tr').length);
    $('div.eventTableUpdTime').html($('div.eventTablePlaceholder').find('div.eventTableUpdTime').html());

    $('div.eventTablePlaceholder').html('');
}
function ajaxRequest() {
    var params = 'obj_name=' + $('div.eventTableObjName').html() + '&' + 'obj_startdate=' + $('div.eventTableStartdate').html();
    if ($('div.eventTableMethod').html() == 'api') {
        params += '&' + 'obj_useapi=on';
    }
    if ($('div.eventTableMethod').html() == 'db') {
        params += '&' + 'obj_usedb=on';
    }
    $.ajax({url: "/rawmethod/get_object_events",
            type: "POST",
            data: params,
            success: ajaxRequestComplete
    });
}
